<template>
    <div class="latiao">
        <div class="la-one" v-for="(item, index) in ww" :key="index">
            <div class="la-one-r">
                <div class="la-one-q">{{ item.name }}</div>
                <div class="la-one-qq"> {{ item.price }}元/袋</div>
            </div>
            <div class="la-one-w">
                <div class="la-one-ww" @click="getName1(index)">-</div>
                <div class="la-one-e">{{ item.status }}</div>
                <div class="la-one-ee" @click="getName(index)">+</div>
            </div>
            <!-- <div class="la-one-w">
                <div class="la-one-ww" @click="getName1(item)">-</div>
                <div class="la-one-e">{{ item.status }}</div>
                <div class="la-one-ee" @click="getName(item)">+</div>
            </div> -->


        </div>
        <div class="la-one-rr" @click="getName3()">支付({{ yy }})</div>
        <div class="la-two" v-if="ee" @click="getName4()">
            <div class="la-two-qq">总价格:{{ yy }}</div>
        </div>

    </div>
</template>

<script>
export default {
    name: "",
    /*1. Vue扩展 */
    extends: "", // extends和mixins都扩展逻辑，需要重点放前面
    mixins: [],
    components: {},
    /* 2. Vue数据 */
    props: {},
    model: { prop: "", event: "" }, // model 会使用到 props
    data() {
        return {
            ww: [],
            ee: false,
            yy: 0,
        };
    },
    computed: {},
    watch: {}, // watch 监控的是 props 和 data，有必要时监控computed
    /* 3. Vue资源 */
    filters: {},
    directives: {},
    /* 4. Vue生命周期 */
    created() {
        const qq = this.getShopList()
        this.ww = qq.result
        let aa = [2, 4]
        let bb = aa
        let cc = aa
        bb[0] = 1
        console.log(cc)
        console.log(aa)

    },
    mounted() { },
    destroy() { },

    /* 5. Vue方法 */
    methods: {
        getShopList() {
            const data = {
                result: [
                    {
                        name: "苹果",
                        price: 10,
                        status: 0
                    },
                    {
                        name: "栗子",
                        price: 20,
                        status: 0
                    },
                    {
                        name: "香蕉",
                        price: 30,
                        status: 0
                    },
                    {
                        name: "菠萝",
                        price: 40,
                        status: 0
                    },
                    {
                        name: "西红柿",
                        price: 5,
                        status: 0
                    },
                ],
            };
            return data
        },
        getName(tt) {
            this.ww[tt].status = this.ww[tt].status + 1
            this.getName2()
        },
        getName1(tt) {
            if (this.ww[tt].status > 0) {
                this.ww[tt].status = this.ww[tt].status - 1
            }
            this.getName2()
        },

        getName2() {
            this.yy = 0
            this.ww.forEach((a, b) => {
                this.yy = this.yy + a.price * a.status
            });
        },
        getName3() {
            this.getName2()
            this.ee = true
        },
        getName4() {
            // 获取列表数据 存了一个新地址  （return 数据 才会有新的地址）
            const cc = this.getShopList()
            this.ww = cc.result
            // 计算总价格
            this.getName2()
            this.ee = false
        },

        // getName(tt) {
        //     tt.status = tt.status + 1
        // },
        // getName1(tt) {
        //     if (tt.status > 0) {
        //         tt.status = tt.status - 1
        //     }
        // },
    }
};
</script>


<style scoped lang="scss">
.latiao {
    width: 100%;
    height: 100vh;
    border: 1px solid red;

    .la-one {
        height: 150px;
        margin: 15px 10px 0 10px;
        border: 1px solid red;
        display: flex;
        background-color: antiquewhite;

        .la-one-r {
            margin: 15px 10px 0 10px;

            .la-one-q {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                color: brown;
            }

            .la-one-qq {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                margin-top: 15px;
                color: brown;
            }

            .la-one-qqq {
                height: 35px;
                border: 1px solid red;
                width: 110px;
                text-align: center;
                line-height: 35px;
                margin-top: 15px;
                color: brown;
            }
        }

        .la-one-w {
            margin-left: auto;
            display: flex;
            align-items: center;

            .la-one-ww {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                color: red;
                border-radius: 5px;
            }

            .la-one-e {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                margin-left: 10px;
                color: red;
                border-radius: 5px;
            }

            .la-one-ee {
                height: 35px;
                width: 35px;
                border: 1px solid red;
                text-align: center;
                line-height: 35px;
                font-size: 20px;
                font-weight: 500;
                margin-left: 10px;
                color: red;
                border-radius: 5px;
            }
        }
    }

    .la-one-rr {
        height: 40px;
        border: 1px solid red;
        border-radius: 10px;
        background-color: blue;
        font-size: 17px;
        font-weight: 600;
        color: aliceblue;
        text-align: center;
        line-height: 40px;
        position: fixed;
        bottom: 0;
        right: 15px;
        left: 15px;


    }

    .la-two {
        bottom: 0;
        top: 0;
        left: 0;
        right: 0;
        position: fixed;
        background-color: rgba(0, 0, 0, 0.2);
        justify-content: center;
        align-items: center;
        display: flex;

        .la-two-qq {
            line-height: 60px;
            height: 60px;
            width: 300px;
            text-align: center;
            font-size: 24px;
            font-weight: 600;
            color: red;
            background-color: white;
            border-radius: 10px;
        }
    }
}
</style>